# PYTHON script
import meta
import json
from meta import models, results
import os


def main():
    window_name = 'MetaPost'
    model_filename = r"{model_filename}"
    result_filename = r"{result_filename}"
    deck = "ABAQUS"
    states = 'all'
    m = models.LoadModel(window_name, model_filename, deck)
    node_info = []
    if m:
        model_nodes = m.get_nodes("all")
        data = 'Displacements'
        new_resultsets = results.LoadScalar(
            m.id, result_filename, deck, states, data)
        res = new_resultsets[1]
        for n, item in list(zip(model_nodes, res.get_nodal_scalar())):
            temp = dict()
            temp["node_id"] = n.id
            temp["x"] = n.x
            temp["y"] = n.y
            temp["z"] = n.z
            temp["displacement"] = item.value
            node_info.append(temp)
        with open(os.path.join(r"{work_dir}", "output.json"), "w") as file:
            json.dump(node_info, file)


if __name__ == "__main__":
    main()
#!EOF